home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscClipTextPalette / MiscClipTextFieldInspector.m < prev    next >
Encoding:
Text File  |  1995-07-21  |  5.7 KB  |  214 lines

  1. //
  2. //    MiscClipTextFieldInspector.m -- IB inspector of MiscClipTextField(Cell)
  3. //        Written and Copyright (c) 1995 by Balazs Pataki. 
  4. //                Version 1.0.  All rights reserved.
  5. //
  6. //        This notice may not be removed from this source code.
  7. //
  8. //    This object is included in the MiscKit by permission from the author
  9. //    and its use is governed by the MiscKit license, found in the file
  10. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  11. //    for a list of all applicable permissions and restrictions.
  12. //    
  13.  
  14. // Most of the code in this inspector is borrowed form  Mike Ferris's 
  15. // MORegexTextCellInspector of MOKit
  16. // Mike Ferris, Copyright 1993, all rights reserved.
  17.  
  18. #import "MiscClipTextFieldInspector.h"
  19. #import <misckit/MiscClipTextFieldCell.h>
  20. #import <misckit/MiscClipTextField.h>
  21. #import <misckit/MiscPathField.h>
  22. #import <objc/objc-runtime.h>
  23.  
  24. #define CLASS_VERSION    0
  25. #define CLASS_NAME        "MiscClipTextFieldInspector"
  26.  
  27.  
  28. #define BG_NONE_TAG        0
  29. #define BG_BLACK_TAG    1
  30. #define BG_DKGRAY_TAG    2
  31. #define BG_LTGRAY_TAG    3
  32. #define BG_WHITE_TAG    4
  33.  
  34. #define TG_BLACK_TAG    0
  35. #define TG_DKGRAY_TAG    1
  36. #define TG_LTGRAY_TAG    2
  37. #define TG_WHITE_TAG    3
  38.  
  39. #define ALIGN_LEFT_TAG        0
  40. #define ALIGN_CENTER_TAG    1
  41. #define ALIGN_RIGHT_TAG        2
  42.  
  43. #define BORDER_NONE_TAG        0
  44. #define BORDER_LINE_TAG        1
  45. #define BORDER_BEZEL_TAG    2
  46.  
  47. #define LEFT_TAG        0
  48. #define RIGHT_TAG        1
  49.  
  50.  
  51. #define NIB_TYPE                            "nib"
  52. #define NIB_NAME                            "MiscClipTextFieldInspector"
  53.  
  54.  
  55. @implementation MiscClipTextFieldInspector
  56.  
  57. + initialize
  58. // Set the version.
  59. {
  60.     if (self == objc_lookUpClass(CLASS_NAME))  {
  61.         [self setVersion:CLASS_VERSION];
  62.     }
  63.     return self;
  64. }
  65.  
  66. - init
  67. // Load our nib file.
  68. {
  69.     char buf[MAXPATHLEN+1];
  70.     id bundle;
  71.     
  72.     [super init];
  73.     
  74.     // load our nib file.
  75.     bundle = [NXBundle bundleForClass:[self class]];
  76.     [bundle getPath:buf forResource:NIB_NAME ofType:NIB_TYPE];
  77.     [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  78.     
  79.     return self;
  80. }
  81.  
  82. - ok:sender
  83. // set the text field-ish stuff and the allowEmptyString attribute.  
  84. // The patternButtonAction takes care of the regex stuff.  The 
  85. // optionCheckboxAction takes care of editable, selectable, scrollable.
  86. {
  87.     int bgTag = [backgroundGrayMatrix selectedTag];
  88.     int tgTag = [textGrayMatrix selectedTag];
  89.     int alTag = [alignmentMatrix selectedTag];
  90.     int boTag = [borderMatrix selectedTag];
  91.     int clTag = [clipOnMatrix selectedTag];
  92.     
  93.     const char *stringVal=NULL;
  94.     
  95.     if (bgTag == BG_NONE_TAG)  {
  96.         [object setBackgroundGray:-1.0];
  97.     }  else if (bgTag == BG_BLACK_TAG)  {
  98.         [object setBackgroundGray:NX_BLACK];
  99.     }  else if (bgTag == BG_DKGRAY_TAG)  {
  100.         [object setBackgroundGray:NX_DKGRAY];
  101.     }  else if (bgTag == BG_LTGRAY_TAG)  {
  102.         [object setBackgroundGray:NX_LTGRAY];
  103.     }  else  {
  104.         [object setBackgroundGray:NX_WHITE];
  105.     }
  106.     if (tgTag == TG_BLACK_TAG)  {
  107.         [object setTextGray:NX_BLACK];
  108.     }  else if (tgTag == TG_DKGRAY_TAG)  {
  109.         [object setTextGray:NX_DKGRAY];
  110.     }  else if (tgTag == TG_LTGRAY_TAG)  {
  111.         [object setTextGray:NX_LTGRAY];
  112.     }  else  {
  113.         [object setTextGray:NX_WHITE];
  114.     }
  115.     if (alTag == ALIGN_LEFT_TAG)  {
  116.         [object setAlignment:NX_LEFTALIGNED];
  117.     }  else if (alTag == ALIGN_CENTER_TAG)  {
  118.         [object setAlignment:NX_CENTERED];
  119.     }  else  {
  120.         [object setAlignment:NX_RIGHTALIGNED];
  121.     }
  122.     if (boTag == BORDER_NONE_TAG)  {
  123.         [object setBordered:NO];
  124.         [object setBezeled:NO];
  125.     }  else if (boTag == BORDER_LINE_TAG)  {
  126.         [object setBordered:YES];
  127.     }  else  {
  128.         [object setBezeled:YES];
  129.     }
  130.  
  131.     [object setTag:[tagForm intValueAt:0]];
  132.  
  133.     // My settings
  134.     if (clTag == LEFT_TAG)
  135.         [object setClipOnRight:NO];
  136.     else
  137.         [object setClipOnRight:YES];
  138.  
  139.     if (stringVal=[clipperStringField stringValue])
  140.         [object setClipperString:stringVal];
  141.     //else
  142.     //    [object setClipperString:"..."];
  143.     [object setClipDelimiters:[clipDelimitersField stringValue]];
  144.  
  145.     return [super ok:sender];
  146. }
  147.  
  148. - revert:sender
  149. // fill in the inspector with the attributes of "object"
  150. {    
  151.     float bg = [object backgroundGray], tg = [object textGray];
  152.     int alignment = [object alignment];
  153.     BOOL isBordered = [object isBordered], isBezeled = [object isBezeled];
  154.     
  155.     if (bg < 0)  {
  156.         [backgroundGrayMatrix selectCellAt:0:BG_NONE_TAG];
  157.     }  else  if ((bg >= 0) && (bg < .2))  {
  158.         [backgroundGrayMatrix selectCellAt:0:BG_BLACK_TAG];
  159.     }  else  if ((bg >= .2) && (bg < .45))  {
  160.         [backgroundGrayMatrix selectCellAt:0:BG_DKGRAY_TAG];
  161.     }  else  if ((bg >= .45) && (bg < .8))  {
  162.         [backgroundGrayMatrix selectCellAt:0:BG_LTGRAY_TAG];
  163.     }  else  if (bg >= .8)  {
  164.         [backgroundGrayMatrix selectCellAt:0:BG_WHITE_TAG];
  165.     }
  166.     [backgroundGrayMatrix display];
  167.     if (tg < .2)  {
  168.         [textGrayMatrix selectCellAt:0:TG_BLACK_TAG];
  169.     }  else  if ((tg >= .2) && (tg < .45))  {
  170.         [textGrayMatrix selectCellAt:0:TG_DKGRAY_TAG];
  171.     }  else  if ((tg >= .45) && (tg < .8))  {
  172.         [textGrayMatrix selectCellAt:0:TG_LTGRAY_TAG];
  173.     }  else  if (tg >= .8)  {
  174.         [textGrayMatrix selectCellAt:0:TG_WHITE_TAG];
  175.     }
  176.     [textGrayMatrix display];
  177.     if (alignment == NX_LEFTALIGNED)  {
  178.         [alignmentMatrix selectCellAt:0:ALIGN_LEFT_TAG];
  179.     }  else if (alignment == NX_CENTERED)  {
  180.         [alignmentMatrix selectCellAt:0:ALIGN_CENTER_TAG];
  181.     }  else  {
  182.         [alignmentMatrix selectCellAt:0:ALIGN_RIGHT_TAG];
  183.     }
  184.     [alignmentMatrix display];
  185.     if (isBezeled)  {
  186.         [borderMatrix selectCellAt:0:BORDER_BEZEL_TAG];
  187.     }  else if (isBordered)  {
  188.         [borderMatrix selectCellAt:0:BORDER_LINE_TAG];
  189.     }  else  {
  190.         [borderMatrix selectCellAt:0:BORDER_NONE_TAG];
  191.     }
  192.  
  193.     [tagForm setIntValue:[object tag] at:0];
  194.     
  195.     // My settings
  196.     if ([object doesClipOnRight])
  197.         [clipOnMatrix selectCellWithTag:RIGHT_TAG];
  198.     else
  199.         [clipOnMatrix selectCellWithTag:LEFT_TAG];
  200.         
  201.     [clipDelimitersField setStringValue:[[object delimiters] stringValue]];
  202.     [clipperStringField setStringValue:[[object clipper] stringValue]];
  203.  
  204.     return [super revert:sender];
  205. }
  206.  
  207. - (BOOL)wantsButtons
  208. // Our inspector does not have OK or Revert buttons.
  209. {
  210.     return NO;
  211. }
  212.  
  213.  
  214. @end